package iterator.main.iterator;

import iterator.main.person.IPerson;

import java.util.ArrayList;

/**
 * 具体人员迭代器实现
 */
public class PersonIterator implements Iterator {

    //私有属性存储人员列表对象信息
    private final ArrayList<IPerson> personList;
    //存储位置信息 初始值为-1
    private int index = -1;

    public PersonIterator(ArrayList<IPerson> personList) {
        this.personList = personList;
    }

    @Override
    public boolean hasNext() {
        return this.personList != null && (index < this.personList.size() - 1);
    }

    @Override
    public Object next() {
        if (this.personList != null && (index < this.personList.size() - 1)) {
            return this.personList.get(++index);
        }
        return null;
    }

    @Override
    public Object remove() {
        if (this.personList != null) {
        return this.personList.remove(index);
        }
        return null;
    }
}
